package backstage.staff.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import backstage.staff.dao.StaffDao;
import backstage.staff.pojo.Staff;

public class StaffDaoImpl extends HibernateDaoSupport implements StaffDao {

	public Integer seva(Staff s) {
		Integer i = (Integer) getHibernateTemplate().save(s);
		return i;
	}
	
	public void update(Staff s) {
		getHibernateTemplate().update(s);
	}

	public Staff getStaff(String sys_name){
		List<Staff> list = this.getHibernateTemplate().find("from Staff where sysName=? and status=1",sys_name);
		if(list != null){
			return list.get(0);
		}else{
			return null;
		}
	}
	
	public List<Staff> getStaffList(String hql){
		Session session = getHibernateTemplate().getSessionFactory().openSession();
		Query query = session.createQuery(hql);
		//定义从第几条开始查询  
		//query.setFirstResult(1);
		//定义返回的记录数
		//query.setMaxResults(2);
		List<Staff> result = query.list();
		session.close();
		return result;
	}
	
}
